package cn.yunhe.service;

import cn.yunhe.dao.IUserDao;
import cn.yunhe.dao.ProductDao;
import cn.yunhe.entity.Product;
import cn.yunhe.entity.ShoppingCart;
import cn.yunhe.entity.ShoppingCartItem;
import cn.yunhe.util.ShoppingCartUtil;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;



public class CartService {
    SqlSession session=SqlSessionFactoryUtil.getSqlSession();
    private ProductDao productDao=session.getMapper(ProductDao.class);
    private IUserDao userDao=session.getMapper(IUserDao.class);
    public Product getProduct(int productid) {
        return productDao.getProduct(productid);
    }
            //将商品添加到购物车
    public boolean addToCart(int productid, ShoppingCart sc) {
        Product product =productDao.getProduct(productid);

        if(product != null){
            sc.addProduct(product);
            return true;
        }

        return false;
    }
        //将某类商品移出购物车
    public void removeItemFromShoppingCart(ShoppingCart sc, int productid) {
        sc.removeItem(productid);
    }
        //清空购物车
    public void clearShoppingCart(ShoppingCart sc) {
        sc.clear();
    }
        //修改购物车某商品的数量
    public void updateItemQuantity(ShoppingCart sc, int productid, int quantity) {
        sc.updateItemQuantity(productid, quantity);
    }
    public void cash(ShoppingCart shoppingCart,String Username){

    }


}
